package bt.sim.student;

import java.util.HashMap;
import java.util.Map;

import com.jfinal.core.BaseController;
import com.jfinal.plugin.activerecord.Page;





public class StudentController extends BaseController {

	public void read() {
		
		Map<String, String[]> conditions = getParaMap();
				
		Page<Student> pagination = Student.me.paginate(conditions);
		Map<String, Object> map = new HashMap<String, Object>();
		//按照easyui datagrid 数据封装格式进行二次封装
		map.put("rows", pagination.getList());
		map.put("total", pagination.getTotalRow());
		
		renderJson(map);
	}
	public void remove() {
		String delIds = getPara("delIds");
		Map<String, Object> result = new HashMap<String, Object>();
		
		int delNums = Student.me.studentRemove(delIds);
		if(delNums > 0) {
			result.put("success", "true");
			result.put("delNums", delNums);
		} else {
			result.put("errorMsg", "删除失败！");
		}
		renderJson(result);
	}
	public void createOrUpdate() {
		Student student = getNoDomainModal(Student.class);
		
		boolean flag = false;
		if(student.get("stuId") != null) {
			flag = student.update();
		} else {
			flag = student.save();
		}
		
		Map<String, Object> result = new HashMap<String, Object>();
		if(flag) {
			result.put("success", "true");
		} else {
			result.put("errorMsg", "保存失败！");
		}
		renderJson(result);
	}
	
	

}
